package com.cloudfun.campusshare.repo;

import com.cloudfun.campusshare.common.constant.AttachType;
import com.cloudfun.campusshare.entity.AttachmentEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.Collection;
import java.util.List;

/**
 * @author linyangping
 * @date 2019/11/19
 */

public interface AttachmentEntityRepo extends
        JpaRepository<AttachmentEntity, String>,
        JpaSpecificationExecutor<AttachmentEntity> {

    /**
     * 根据fileHash查询附件
     *
     * @param fileHash
     * @return
     */
    AttachmentEntity findByFileHash(String fileHash);

    /**
     * 根据Id查询附件
     *
     * @param ids
     * @return
     */
//    List<AttachmentEntity> findAllById(Collection<String> ids);

    /**
     * 根据主体id和类型查找附件
     *
     * @param subId
     * @param types
     * @return
     */
    List<AttachmentEntity> findAllBySubjectIdAndTypeIn(String subId, Collection<AttachType> types);

    /**
     * 根据主体id和类型查找附件
     *
     * @param subId
     * @param type
     * @return
     */
    List<AttachmentEntity> findAllBySubjectIdAndType(String subId, AttachType type);

    /**
     * 根据主体id查找附件
     *
     * @param subjectId
     * @return
     */
    List<AttachmentEntity> findAllBySubjectId(String subjectId);

    List<AttachmentEntity> findAllBySubjectIdIsNull();
}
